package xin.petstore.framework.filter;

import com.eloancn.common.cache.RedisSpecMethods;
import com.eloancn.common.constant.Constant;
import com.eloancn.common.utils.IPUtils;
import com.eloancn.framework.utils.SpringContextHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.BoundValueOperations;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * @Description：恶意请求拦截
 * @author zsongbo
 * @version 1.0
 * @Copyright (C), 2010-2020
 */

public class AttackReqFilter implements Filter {

	public void doFilter(ServletRequest reg, ServletResponse res, FilterChain chain) throws IOException, ServletException {

		HttpServletRequest request = (HttpServletRequest) reg;
		HttpServletResponse response = (HttpServletResponse) res;
		if (RedisSpecMethods.getInstance().domain(request, response) == 1) {
			response.sendRedirect(Constant.MAIN_TENANCE);
		}else{
			chain.doFilter(request, response);
		}
	}

	public void init(FilterConfig config) throws ServletException {}
	public void destroy() {}

}